#define DEBUG
#include <cstdio>

using namespace std;

const int maxn=2000, maxm=2000;

int board[maxn+1][maxm+1], n, m, ver=1, book[maxn+1][maxm+1], time[maxn+1][maxm+1], warp[maxn+1][maxm+1][2], cnt=0, x=1, y=1;

int min(int a, int b) {
  return a<b ? a : b;
}

int max(int a, int b) {
  return a>b ? a : b;
}

int moveNext(int x, int y) {
  int ny = y%m+1;
  int ax = (x+n-2)%n+1, bx = x, cx = x%n+1;
  if (board[ax][ny]>board[bx][ny] && board[ax][ny]>board[cx][ny]) {
    return ax;
  } else if (board[bx][ny]>board[ax][ny] && board[bx][ny]>board[cx][ny]) {
    return bx;
  } else {
    return cx;
  }
}

class SegmentTree {
public:
  int go[5*maxm+1][maxn+1];

  void init(int o, int l, int r) {
    if (l==r) {
      for (int i=1; i<=n; i++) {
	go[o][i] = moveNext(i, l);
      }
    } else {
      int mid=(l+r)/2;
      init(o*2, l, mid);
      init(o*2+1, mid+1, r);
      for (int i=1; i<=n; i++) {
	go[o][i] = go[o*2+1][go[o*2][i]];
      }
    } 
  }

  void set(int o, int l, int r, int t, int x) {
    if (l==r) {
      go[o][x] = moveNext(x, t);
    } else {
      int mid=(l+r)/2;
      if (t<=mid) {
	set(o*2, l, mid, t, x);
      } else {
	set(o*2+1, mid+1, r, t, x);
      }
      for (int i=1; i<=n; i++) {
	go[o][i] = go[o*2+1][go[o*2][i]];
      }
    }
  }

  int get(int o, int l, int r, int tl, int tr, int x) {
    if (l==tl && r==tr) {
      return go[o][x];
    } else {
      int mid=(l+r)/2, ret=0;
      if (tl<=mid && tr>=l) {
	ret = get(o*2, l, mid, max(l, tl), min(mid, tr), x);
	if (tl<=r && tr>mid) {
	  ret = get(o*2+1, mid+1, r, max(mid+1, tl), min(r, tr), ret);
	}
      } else if (tl<=r && tr>mid) {
	ret = get(o*2+1, mid+1, r, max(mid+1, tl), min(r, tr), x);
      }
      return ret;
    }
  }
};

int read() {
  char c;
  int ret=0;
  for (c=getchar(); c<'0' || c>'9'; c=getchar());
  for (; c>='0' && c<='9'; c=getchar()) {
    ret = ret*10+c-'0';
  }
  return ret;
}

void move(SegmentTree *sgt, int k) {
  for (; k>0;) {
    book[x][y] = ver;
    time[x][y] = cnt;
    if (warp[x][y][0]==ver) {
      k = k%warp[x][y][1];
    }
    if (k>0) {
      if (y+k>m) {
	x = sgt->get(1, 1, m, y, m, x);
	k -= m-y+1;
	cnt += m-y+1;
	y = 1;
      } else {
	x = sgt->get(1, 1, m, y, y+k-1, x);
	y += k;
	cnt += k;
	k = 0;
      }
    }
    if (book[x][y]==ver && warp[x][y][0]!=ver) {
      warp[x][y][0] = ver;
      warp[x][y][1] = cnt-time[x][y];
    }
  }
}

int main() {
  freopen("jump.in", "r", stdin);
  freopen("jump.out", "w", stdout);

  static SegmentTree sgt;
  n=read(), m=read();
  for (int i=1; i<=n; i++) {
    for (int j=1; j<=m; j++) {
      board[i][j] = read();
    }
  }
  sgt.init(1, 1, m);

  int q=read();
  for (int i=1; i<=q; i++) {
    char c;
    for (c=getchar(); c!='m' && c!='c'; c=getchar());
    if (c=='m') {
      int k=read();
      move(&sgt, k);
      printf("%d %d\n", x, y);
    } else {
      int a=read(), b=read(), k=read();
      board[a][b]=k;
      sgt.set(1, 1, m, (b-2+m)%m+1, (a-2+n)%n+1);
      sgt.set(1, 1, m, (b-2+m)%m+1, a);
      sgt.set(1, 1, m, (b-2+m)%m+1, a%n+1);
      ver++;
      cnt=0;
    }
  }

  fclose(stdin);
  fclose(stdout);
  return 0;
}
